/*
 * <nav_recip_rca/line.h>
 * nav_recip_rca
 *
 *
 * Copyright (c) 2008-2012, University of North Carolina at Chapel Hill
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   * Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *   * Neither the name of the University of North Carolina at Chapel Hill nor
 *     the names of its contributors may be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 *
 * Please send all bug reports to <geom@cs.unc.edu>.
 *
 * The authors may be contacted via:
 *
 *     Dept. of Computer Science
 *     201 S. Columbia St.
 *     Frederick P. Brooks, Jr. Computer Science Bldg.
 *     Chapel Hill, N.C. 27599-3175
 *     United States of America
 *
 *     http://gamma.cs.unc.edu/ROS/
 */

#ifndef NAV_RECIP_RCA_LINE_H_
#define NAV_RECIP_RCA_LINE_H_

#include <ostream>
#include <vector>
#include <ros/macros.h>
#include <nav_recip_common/nav_recip_common.h>

namespace nav_recip
{
class Line;

/*!
 * \relates Line
 *
 * A list of Line objects.
 */
typedef std::vector<Line> LineList;

/*!
 * \relates Line
 *
 * An iterator for a LineList.
 */
typedef std::vector<Line>::iterator LineIterator;

/*!
 * \relates Line
 *
 * A \c const iterator for a LineList.
 */
typedef std::vector<Line>::const_iterator LineConstIterator;

/*!
 * \headerfile <nav_recip_rca/line.h>
 *
 * A line in 2D.
 */
class ROS_HELPER_LOCAL Line
{
public:
  /*!
   * Create a new Line.
   */
  ROS_FORCE_INLINE Line() : direction_(), position_() { }

  /*!
   * Create a new Line with given position of a point on the Line and direction.
   */
  ROS_FORCE_INLINE Line(const Vector2& position, const Vector2& direction) : direction_(direction),
      position_(position) { }

  /*!
   * Copy a Line.
   */
  ROS_FORCE_INLINE Line(const Line& line) : direction_(line.direction_), position_(line.position_) { }

  /*!
   * Return the direction of this Line.
   */
  ROS_FORCE_INLINE const Vector2& getDirection() const { return direction_; }

  /*!
   * Return the position of a point on this Line.
   */
  ROS_FORCE_INLINE const Vector2& getPosition() const { return position_; }

  /*!
   * Set the direction of this Line.
   */
  ROS_FORCE_INLINE void setDirection(const Vector2& direction) { direction_ = direction; }

  /*!
   * Set the position of a point on this Line.
   */
  ROS_FORCE_INLINE void setPosition(const Vector2& position) { position_ = position; }

  Vector2 direction_; // Direction.
  Vector2 position_;  // Position of a point on this Line.
};

/*!
 * \relates Line
 *
 * Insert a given Line into a given output stream
 */
ROS_FORCE_INLINE ROS_HELPER_LOCAL std::ostream& operator<<(std::ostream& output_stream, const Line& line)
{
  output_stream << "[ Line: position = " << line.getPosition() << ", direction = " << line.getDirection() << " ]";

  return output_stream;
}
}

#endif // NAV_RECIP_RCA_LINE_H_
